package org.example.day13;


/**
 * 7.1.2 验证TIMED_WAITING
 */
public class MyThread2 extends Thread{
    @Override
    synchronized public void run() {
        try {
            System.out.println("begin sleep");
//            Thread.sleep(10000);
            this.wait();
            System.out.println("end sleep");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            MyThread2 m2 = new MyThread2();
            m2.start();
            Thread.sleep(1000);
            //①  Thread.sleep(10000);     main 方法中的状态: TIMED_WAITING
            //②  this.wait();    main 方法中的状态: WAITING
            System.out.println("main 方法中的状态: " + m2.getState());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
